//一般直接写在一个js文件中
layui.use(['element','form','laytpl','laydate'],function () {
    var form = layui.form,
     laydate = layui.laydate,
    laytpl = layui.laytpl,
    currentdate= $.dateFormat(new Date(),"yyyy-MM-dd");
    laydate.render({
        elem: '#rowOne' //指定元素
        , value: currentdate
    });
    laydate.render({
        elem: '#rowOneTime' //指定元素
        ,type: 'time'
    });

    getRow();
    getRow();
    //添加餐谱项
    $("#addRow").on('click',function(){
        getRow();
    });

    function getRow() {
        var getTpl=document.getElementById('qtsf').innerHTML;
        var $itemsTbody = $("#items_tbody");
        laytpl(getTpl).render({foodDate:currentdate}, function(html){
            $itemsTbody.append( html);
        });
        render_dates();
    }

    function render_dates(){
        var days = $("#items_tbody").find("input[name=foodDate]");
        var times = $("#items_tbody").find("input[name=foodTime]");
        days.each(function () {
            var that = this;
            laydate.render({
                elem: that
            });
        });
        times.each(function () {
                var that = this;
                laydate.render({
                    elem: that
                    ,type: 'time'
                });
        });
    }
    //删除其它收费项目
     delFoodRow = function(that) {
        $(that).closest('tr').remove();
    }

    form.verify({
        burdenFood: function(value, item){ //value：表单的值、item：表单的DOM对象
            if (value.length>10){
                if(value.indexOf(",")==-1 && value.indexOf("，")==-1 && value.indexOf("、")==-1 )
                    return '配料必须用逗号’,‘或者’、‘分开';
            }
        }
    });

});